//
//  MainTabbarController.m
//  AnecdotesDemo
//
//  Created by LYoung on 15/10/13.
//  Copyright (c) 2015年 LYoung. All rights reserved.
//

#import "MainTabbarController.h"
#import "MainNavgationController.h"
#import "MineController.h"

@interface MainTabbarController()

@end

@implementation MainTabbarController



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    if (is_IOS_8) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    [self addParentsChildViewControllers];
}

#pragma mark  --家长的tabbar    1
- (void)addParentsChildViewControllers{
    
    NSArray *buttonImages = @[@"homework", @"chat", @"find",@"more"];
    NSArray *buttonImagesSelected = @[@"homework_select", @"chat__select", @"find_select",@"more__select"];

    MineController *moreVC = [[MineController alloc]init];
    [self addChildViewController:moreVC title:@"我" image:buttonImages[3] selectedImage:buttonImagesSelected[3]];
    
}


#pragma mark -添加一个控制器
/**
 *  添加一个子控制器
 *
 *  @param childController 控制器
 *  @param title           title
 *  @param image           image
 *  @param selectedImage   selectedImage
 */
-(void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    //1.tababr标题
    childController.tabBarItem.title = title;
    UIImage *normal = [UIImage imageNamed:image];
    UIImage *selected = [UIImage imageNamed:selectedImage];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor], NSForegroundColorAttributeName, NSFontAttributeName , FoneSize12, nil] forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MAIN_Color, NSForegroundColorAttributeName, NSFontAttributeName , FoneSize12, nil] forState:UIControlStateSelected];
    
    if (is_IOS_8) {
        childController.tabBarItem.image = [normal imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childController.tabBarItem.selectedImage = [selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }else{
        childController.tabBarItem.selectedImage = selected;
    }
    
    //2.包装导航控制器
    childController.title = title;
    MainNavgationController *mainNav = [[MainNavgationController alloc] initWithRootViewController:childController];
    
    [self addChildViewController:mainNav];
}


@end
